package com.label.web.controller.prototype;


import com.label.common.core.controller.BaseController;
import com.label.common.core.domain.AjaxResult;
import com.label.common.core.page.TableDataInfo;
import com.label.manager.domain.Project;
import com.label.manager.service.IProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/prototype/project")
public class ProjectController extends BaseController {

    @Autowired
    private IProjectService projectService;

    /**
     * 查询项目列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Project project) {
        startPage();
        List<Project> list = projectService.selectProjectList(project);
        return getDataTable(list);
    }

    /**
     * 通过项目ID查询项目信息
     */
    @GetMapping(value = "/{projectId}")
    public AjaxResult getInfo(@PathVariable Long projectId) {
        return success(projectService.selectProjectById(projectId));
    }

    /**
     * 删除项目
     *
     * @param projectId
     * @return
     */
    @DeleteMapping("/{projectId}")
    public AjaxResult remove(@PathVariable Long projectId) {
        return toAjax(projectService.deleteProjectById(projectId));
    }

    /**
     * 关闭项目
     *
     * @param projectId
     * @return
     */
    @PutMapping("/close/{projectId}")
    public AjaxResult close( @PathVariable Long projectId) {
        return toAjax(projectService.closeProject(projectId));
    }

    /**
     * 新增项目
     */
    @PostMapping
    public AjaxResult add(@RequestBody Project project) {
        return toAjax(projectService.insertProject(project));
    }

    /**
     * 修改项目
     */
    @PutMapping
    public AjaxResult edit(@RequestBody Project project) {
        return toAjax(projectService.updateProject(project));
    }
}
